package com.haiya.memento.casestudy;

public class GirlStack {
    private Girl girl[];
    private int top;

    public GirlStack() {
        girl = new Girl[5];
        top = -1;
    }

    public boolean push(Girl g) {
        System.out.println("暂存美女: " + g.getName());
        if (top >= 4) {
            System.out.println("你太花心了，变来变去的！");
            return false;
        } else {
            girl[++top] = g;
            return true;
        }
    }

    public Girl pop() {
        Girl g = null;
        if (top <= 0) {
            System.out.println("美女栈空了！");
            g = girl[0];
        } else {
            g = girl[top--];
        }
        System.out.println("回退美女: " + g.getName());
        return g;
    }
}
